package twinb.interest;

import java.util.HashMap;
import java.util.Map;

import twinb.Utils;

public class InterestModelBase<TID> implements InterestModel<TID>
{
    private Map<TID, Double> interests = new HashMap<TID, Double>();
    
    protected void addInterest(TID id, double interest)
    {
        double preValue = Utils.mapTryGet(interests, id, 0.0);
        interests.put(id, interest + preValue);
    }
    
    @Override
    public double getInterest(TID id)
    {
        return Utils.mapTryGet(interests, id, 0.0);
    }
    
    @Override
    public void decay()
    {
        for (TID id : interests.keySet())
        {
            double preValue = interests.get(id);
            interests.put(id, preValue * decayFactor);
        }
    }

    @Override
    public Map<TID, Double> getVectorRepresentation()
    {
        return interests;
    }
}
